package com.gzwanchuang.xhgj.ui.page.home;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.ViewModelProviders;

import com.gzwanchuang.architecture.utils.GsonUtils;
import com.gzwanchuang.xhgj.R;
import com.gzwanchuang.xhgj.bridge.request.HomeRequestViewModel;
import com.gzwanchuang.xhgj.bridge.state.home.XinCardViewModel;
import com.gzwanchuang.xhgj.databinding.FragmentXinCardDetailBinding;
import com.gzwanchuang.xhgj.help.DialogUtils;
import com.gzwanchuang.xhgj.proto.Bank;
import com.gzwanchuang.xhgj.ui.base.BaseFragment;

/**
 * 文件名 : HomeRootFragment
 * 创建者 : MangoWang
 * 创建日期 : 2019/12/24 16:20
 * 微信 : MangoWaWang
 * 邮箱 : 763482205@qq.com
 * 描述 : TODO
 */
public class XinCardDetailFragment extends BaseFragment {
    private FragmentXinCardDetailBinding mBinding;
    private XinCardViewModel mViewModel;
    private HomeRequestViewModel mRequestViewModel;


    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mViewModel = ViewModelProviders.of(this).get(XinCardViewModel.class);
        mRequestViewModel = ViewModelProviders.of(this).get(HomeRequestViewModel.class);
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_xin_card_detail, container, false);
        mBinding = FragmentXinCardDetailBinding.bind(view);
        mBinding.setClick(new ClickProxy());
        mBinding.setVm(mViewModel);
        return view;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        mRequestViewModel.getErrorString().observe(this, s -> {
            hideProgress();
            showShortToast(s);
        });
        mRequestViewModel.getResultString().observe(this, s -> {
            hideProgress();
            showShortToast(s);
            nav().navigateUp();
        });
        Bank.bank bean = GsonUtils.jsonToBean(getArguments().getString("data"), Bank.bank.class);
        mViewModel.bean.set(bean);
        if (bean.getIsSupport().equals("1"))
        {
            mViewModel.texVis.set(false);
            mViewModel.vipVis.set(true);
        }else
        {
            mViewModel.texVis.set(true);
            mViewModel.vipVis.set(false);
        }
    }


    public class ClickProxy {
        public void back() {
            nav().navigateUp();
        }

        public void more() {
            DialogUtils.showBottomMenuDialogAndHit(mActivity, "", "解除绑定", "", new DialogUtils.BottomMenuDialogImpl() {
                @Override
                public void onMenu1() {
                    showProgress();
                    mRequestViewModel.unbind_card(mViewModel.bean.get().getId());
                }

                @Override
                public void onMenu2() {
                }
            });
        }
    }
}
